using AspDotNet.Core7.First.Middlewares;
using AspDotNet.Core7.First.Models;
using AspDotNet.Core7.First.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

[ViewComponent]
internal class Program
{
    private static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Add services to the container.
        builder.Services.AddControllersWithViews();
        builder.Services.AddRazorPages();
        builder.Services.AddSingleton<TotalUsers>();
        builder.Services.Configure<DataBaseConnection>(builder.Configuration.GetSection("DBConnection"));

        var app = builder.Build();

        // Configure the HTTP request pipeline.
        if (!app.Environment.IsDevelopment())
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();


        }

        if (app.Environment.IsStaging())
        {
            // do something
        }

        if (app.Environment.IsProduction())
        {
            // do something

            app.UseResponseEditingMiddleware();
            app.UseRequestEditingMiddleware();
            app.UseShortCircuitMiddleware();
            app.UseContentMiddleware();

        }

        if (app.Environment.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseStatusCodePages();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();
        app.UseAuthentication();

        app.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");

        app.MapDefaultControllerRoute();

        app.Run();
    }
}